package com.hjx.service.impl;

import com.hjx.entity.SysRole;
import com.hjx.entity.SysUserRole;
import com.hjx.mapper.SysUserRoleMapper;
import com.hjx.service.SysUserRoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * <p>Title:</p>
 * <p>Description:</p>
 *
 * @author hjx
 * @date 2020/6/16 - 11:41
 */
@Service
@Transactional
public class SysUserRoleServiceImpl implements SysUserRoleService {
    @Resource
    SysUserRoleMapper sysUserRoleMapper;

    @Override
    public List<SysRole> findRoleByUid(String uid) {
        if (!StringUtils.isEmpty(uid) && !StringUtils.isBlank(uid)) {
            return sysUserRoleMapper.findRoleByUid(uid);
        }
        return null;
    }

    @Override
    public List<SysRole> findNoGetRoleByUid(String uid) {
        if (!StringUtils.isEmpty(uid) && !StringUtils.isBlank(uid)) {
            return sysUserRoleMapper.findNoGetRoleByUid(uid);
        }
        return null;
    }

    @Override
    public boolean insertBatch(SysUserRole sysUserRole) {
        return sysUserRoleMapper.insertBatch(sysUserRole);
    }

    @Override
    public boolean delete(SysUserRole sysUserRole) {
        Set<String> urids = sysUserRoleMapper.findUridByUid(sysUserRole.getUid());
        urids.removeAll(sysUserRole.getUrids());
        return sysUserRoleMapper.delete(urids);
    }
}
